home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Devices and Hardware / Velocity Engine / VelEng FFT / vBigDSP / vBigDSP.h < prev   
Encoding:
Text File  |  2000-09-28  |  10.6 KB  |  256 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        vBigDSP.c
  3.  
  4.     Contains:    AltiVec-based Implementation of DSP routines (real & complex FFT, convolution)
  5.  
  6.     Version:    1.0
  7.  
  8.     Copyright:    © 1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.                 10/12/99    JK        Created
  13.  
  14. */
  15.  
  16. /////////////////////////////////////////////////////////////////////////////////
  17. //      File Name: vBigDSP.c                                                   //
  18. //                                                                               //
  19. //        This library provides a set of DSP routines, implemented using the       //
  20. //        AltiVec instruction set.                                                 //
  21. //                                                                               //
  22. //                                                                             //
  23. //      Copyright © 1999 Apple Computer, Inc.  All rights reserved.            //
  24. //                                                                             //
  25. //      Version 1.0                                                            //
  26. //                                                                             //
  27. /////////////////////////////////////////////////////////////////////////////////
  28.  
  29. /*
  30.     Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  31.                 ("Apple") in consideration of your agreement to the following terms, and your
  32.                 use, installation, modification or redistribution of this Apple software
  33.                 constitutes acceptance of these terms.  If you do not agree with these terms,
  34.                 please do not use, install, modify or redistribute this Apple software.
  35.  
  36.                 In consideration of your agreement to abide by the following terms, and subject
  37.                 to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  38.                 copyrights in this original Apple software (the "Apple Software"), to use,
  39.                 reproduce, modify and redistribute the Apple Software, with or without
  40.                 modifications, in source and/or binary forms; provided that if you redistribute
  41.                 the Apple Software in its entirety and without modifications, you must retain
  42.                 this notice and the following text and disclaimers in all such redistributions of
  43.                 the Apple Software.  Neither the name, trademarks, service marks or logos of
  44.                 Apple Computer, Inc. may be used to endorse or promote products derived from the
  45.                 Apple Software without specific prior written permission from Apple.  Except as
  46.                 expressly stated in this notice, no other rights or licenses, express or implied,
  47.                 are granted by Apple herein, including but not limited to any patent rights that
  48.                 may be infringed by your derivative works or by other works in which the Apple
  49.                 Software may be incorporated.
  50.  
  51.                 The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  52.                 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  53.                 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  54.                 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  55.                 COMBINATION WITH YOUR PRODUCTS.
  56.  
  57.                 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  58.                 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  59.                 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  60.                 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  61.                 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  62.                 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  63.                 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  64. */
  65.  
  66.  
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #endif
  70.  
  71. //////////////////////////////////////////////////////////
  72. // constants for foward/inverse flags for complex FFT    //
  73. //////////////////////////////////////////////////////////
  74. #define    IFLAG_FFT_FORWARD    (-1)
  75. #define    IFLAG_FFT_INVERSE    (1)
  76.  
  77. //////////////////////////////////////////////////////////
  78. //    length above which we no longer use                 //
  79. //    the ping pong FFT (for speed reasons)                //
  80. //////////////////////////////////////////////////////////
  81. #define PINGPONG_FFT_MAXLEN                    (1<<15)
  82.  
  83. //////////////////////////////////////////////////////////
  84. //    minimum length for calling AltiVec implementation    //
  85. //     of ping pong FFT    (because of implementation         //    
  86. //    details, algorithm will not work on lengths            //
  87. // below this).                                            //
  88. //////////////////////////////////////////////////////////
  89. #define ALTIVEC_COMPLEX_MIN_LENGTH            16
  90.  
  91. //////////////////////////////////////////////////////////
  92. //    minimum length for calling AltiVec implementation    //
  93. //     of real FFT    (because of implementation                 //    
  94. //    details, algorithm will not work on lengths            //
  95. // below this).                                            //
  96. //////////////////////////////////////////////////////////
  97. #define ALTIVEC_REAL_MIN_LENGTH                32
  98.  
  99. //////////////////////////////////////////////////////////
  100. // minimum length at which the columnwise FFT is faster    //
  101. // than the standard ping pong FFT.                        //
  102. //////////////////////////////////////////////////////////
  103. #define ALTIVEC_COLUMNWISE_FFT_BREAKOVER    (1<<15)
  104.  
  105.  
  106. //////////////////////////////////////////////////////////
  107. //    ShutdownFFT                                            //
  108. //                                                        //
  109. // deallocate any temporary buffer and sin/cos table    //
  110. // lookup buffers used by FFT code                        //
  111. //////////////////////////////////////////////////////////
  112. void     ShutdownFFT();
  113.  
  114. //////////////////////////////////////////////////////////
  115. //    FFTComplex                                            //
  116. //                                                        //
  117. //    forward/inverse FFT for complex signals                //
  118. //                                                        //
  119. //    data            address of signal (16-byte aligned)    //
  120. //    length            number of complex elements in signal//
  121. //    isign            one of     IFLAG_FFT_FORWARD            //
  122. //                            IFLAG_FFT_INVERSE            //
  123. //                    for forward or inverse FFT            //
  124. //////////////////////////////////////////////////////////
  125. OSErr     FFTComplex(float *data, long length, long isign);
  126.  
  127. //////////////////////////////////////////////////////////
  128. // FFTRealForward                                        //
  129. //                                                        //
  130. // forward FFT for real signal                            //
  131. //                                                        //
  132. //    data            address of signal (16-byte aligned)    // 
  133. //    len                number of complex elements in signal//
  134. //////////////////////////////////////////////////////////
  135. OSErr    FFTRealForward(float *data, unsigned long len);
  136.  
  137.  
  138. //////////////////////////////////////////////////////////
  139. // FFTRealInverse                                        //
  140. //                                                        //
  141. // inverse FFT for real signal                            //
  142. //                                                        //
  143. //    data            address of signal (16-byte aligned)    // 
  144. //    len                number of complex elements in signal//
  145. //////////////////////////////////////////////////////////
  146. OSErr    FFTRealInverse(float *data, unsigned long len);
  147.  
  148.  
  149.  
  150. //////////////////////////////////////////////////////////
  151. // ConvolveComplexAltivec                                //
  152. //                                                        //
  153. // calculates convolution of two complex signals        //
  154. //                                                        //
  155. //    x                address of first complex signal for    // 
  156. //                    complex convolution (is replaced     // 
  157. //                    with FFT(x)    (16-byte aligned)        //
  158. //    y                address of first complex signal for    // 
  159. //                    complex convolution (is replaced     // 
  160. //                    with convolution of x, y             //
  161. //                    (16-byte aligned)                    //
  162. //    n                number of complex elems in signals    //
  163. //////////////////////////////////////////////////////////
  164. OSErr     ConvolveComplexAltivec(float *    x, float *    y, int   n);
  165.  
  166. //////////////////////////////////////////////////////////
  167. // ConvolveRealAltivec                                    //
  168. //                                                        //
  169. // calculates convolution of two real signals            //
  170. //                                                        //
  171. //    x                address of first real signal for    // 
  172. //                    real convolution (is replaced         // 
  173. //                    with FFT(x) (16-byte aligned)        //
  174. //    y                address of first real signal for    // 
  175. //                    real convolution (is replaced         // 
  176. //                    with convolution of x, y            //
  177. //                    (16-byte aligned)                    //
  178. //    n                number of real elems in signals        //
  179. //////////////////////////////////////////////////////////
  180. OSErr      ConvolveRealAltivec(float *    x, float *    y, int   n);
  181.  
  182. //////////////////////////////////////////////////////////
  183. // FFT2DComplex                                            //
  184. //                                                        //
  185. // forward/inverse FFT for 2D complex signal            //
  186. //                                                        //
  187. //    data            address of signal (16-byte aligned)    // 
  188. //    width            width of 2D array of complex signal    //
  189. //    height            height of 2D array of complex signal//
  190. //    isign            one of     IFLAG_FFT_FORWARD            //
  191. //                            IFLAG_FFT_INVERSE            //
  192. //                    for forward or inverse FFT            //
  193. //////////////////////////////////////////////////////////
  194. OSErr    FFT2DComplex(float *data, unsigned long width, unsigned long height, long iflag);
  195.  
  196. //////////////////////////////////////////////////////////
  197. // FFT2DRealForward                                        //
  198. //                                                        //
  199. // forward FFT for 2D real signal                        //
  200. //                                                        //
  201. //    data            address of signal (16-byte aligned)    // 
  202. //    width            width of 2D array of real signal    //
  203. //    height            height of 2D array of real signal    //
  204. //////////////////////////////////////////////////////////
  205. OSErr    FFT2DRealForward(float *data, unsigned long width, unsigned long height);
  206.  
  207. //////////////////////////////////////////////////////////
  208. // FFT2DRealInverse                                        //
  209. //                                                        //
  210. // forward FFT for 2D real signal                        //
  211. //                                                        //
  212. //    data            address of signal (16-byte aligned)    // 
  213. //    width            width of 2D array of real signal    //
  214. //    height            height of 2D array of real signal    //
  215. //////////////////////////////////////////////////////////
  216. OSErr    FFT2DRealInverse(float *data, unsigned long width, unsigned long height);
  217.  
  218. //////////////////////////////////////////////////////////
  219. // ConvolveComplexAltivec2D                                //
  220. //                                                        //
  221. // 2D convolution for two complex signals                //
  222. //                                                        //
  223. //    x                address of first complex signal for    // 
  224. //                    complex convolution (is replaced    // 
  225. //                    with FFT(x) (16-byte aligned)        //
  226. //    y                address of first complex signal for    // 
  227. //                    complex convolution (is replaced    // 
  228. //                    with convolution of x, y            //
  229. //                    (16-byte aligned)                    //
  230. //    width            width of 2D array of complex signal    //
  231. //    height            height of 2D array of complex signal//
  232. //////////////////////////////////////////////////////////
  233. OSErr     ConvolveComplexAltivec2D(float *    x, float *    y, long     width, long    height);
  234.  
  235. //////////////////////////////////////////////////////////
  236. // ConvolveRealAltivec2D                                //
  237. //                                                        //
  238. // 2D convolution for two real signals                    //
  239. //                                                        //
  240. //    x                address of first real signal for    // 
  241. //                    real convolution (is replaced        // 
  242. //                    with FFT(x) (16-byte aligned)        //
  243. //    y                address of first real signal for    // 
  244. //                    real convolution (is replaced        // 
  245. //                    with convolution of x, y            //
  246. //                    (16-byte aligned)                    //
  247. //    width            width of 2D array of real signal    //
  248. //    height            height of 2D array of real signal    //
  249. //////////////////////////////////////////////////////////
  250. OSErr     ConvolveRealAltivec2D(float *    x, float *    y, long width, long    height);
  251.  
  252.  
  253. #ifdef __cplusplus
  254. } // extern "C" {
  255. #endif
  256.